<template>
  <div class="head">
    <div class="tit">
      <button
        id="1"
        :class="id === '1' ? 'active' : ''"
        class="tex1"
        @click="tab('1')"
      >
        业务员账单报表
      </button>
      <button
        id="2"
        :class="id === '2' ? 'active' : ''"
        class="tex1"
        @click="tab('2')"
      >
        网点派费直达报表
      </button>
    </div>
    <div class="line" />
    <el-row>
      <el-col :span="24">
        <div v-if="id === '1'" class="title1">
          <el-form
            ref="form"
            style="
              display: flex;
              flex-wrap: wrap;
              margin-top: 24px;
              justify-content: space-between;
            "
            :model="form"
            label-width="80px"
          >
            <el-form-item style="margin-left: 0" class="text" label="日期">
              <el-date-picker
                v-model="value"
                type="daterange"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd"
                style="width: 708px"
                @change="changeTime"
              />
            </el-form-item>
            <el-form-item class="text" label="网点名称">
              <el-select
                v-model="form.networkName"
                :disabled="true"
                placeholder="辽宁盘锦公司"
                style="width: 286px"
              >
                <el-option label="辽宁盘锦公司" :value="1" />
              </el-select>
            </el-form-item>
            <el-form-item class="text" label="承包区名">
              <el-select
                v-model="form.contractAreaNameId"
                class="input"
                placeholder="请选择"
                style="width: 286px"
              >
                <el-option
                  v-for="item in ShowCoverAreaList"
                  :key="item.id"
                  :label="item.networkName"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
            <div>
              <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
                <el-button @click="khClear">重置</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div v-if="id === '1'" class="title1">
          <el-form
            ref="form"
            style="
              display: flex;
              justify-content: space-between;
              flex-wrap: wrap;
            "
            :model="form"
            label-width="80px"
          >
            <div
              style="
                display: flex;
                justify-content: space-between;
                flex-wrap: wrap;
                width: 1266px;
              "
            >
              <el-form-item class="text" label="业务员名">
                <el-select
                  v-model="form.salesmanId"
                  class="input"
                  placeholder="请选择"
                  style="width: 286px"
                >
                  <el-option
                    v-for="item in TakeManList"
                    :key="item.id"
                    :label="item.solicitor"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
              <el-form-item class="text" label="汇总维度">
                <el-select
                  v-model="form.collectType"
                  class="input"
                  placeholder="请选择"
                  style="width: 286px"
                >
                  <el-option label="按天" value="1" />
                  <el-option label="按时间段" value="2" />
                </el-select>
              </el-form-item>
              <div
                style="
                  font-size: 18px;
                  font-family: Source Han Sans CN;
                  font-weight: 400;
                  color: #ee3000;
                  width: 420px;
                  text-align: center;
                "
              >
                请先选择网点或承包区才有数据
              </div>
            </div>
            <div>
              <el-form-item>
                <el-button @click="onSubmit"
                  ><i class="el-icon-upload2" />导出</el-button
                >
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div v-if="id === '2'" class="title1">
          <el-form
            ref="form"
            style="
              display: flex;
              flex-wrap: wrap;
              margin-top: 24px;
              justify-content: space-between;
            "
            :model="form1"
            label-width="80px"
          >
            <el-form-item style="margin-left: 0" class="text" label="日期">
              <el-date-picker
                v-model="value"
                type="daterange"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd"
                style="width: 708px"
                @change="changeTime"
              />
            </el-form-item>
            <el-form-item class="text" label="汇总层级" required>
              <el-select
                v-model="value1"
                placeholder="请选择"
                style="width: 286px"
                @change="changeType"
              >
                <el-option label="网点" value="1" />
                <el-option label="网点+承包区" value="2" />
                <el-option label="网点+承包区+业务员" value="3" />
              </el-select>
            </el-form-item>
            <el-form-item class="text" label="网点名称">
              <el-select
                v-model="form1.networkName"
                :disabled="true"
                placeholder="辽宁盘锦公司"
                style="width: 286px"
              >
                <el-option label="辽宁盘锦公司" value="1" />
              </el-select>
            </el-form-item>
            <div>
              <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
                <el-button @click="khClear">重置</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div v-if="id === '2'" class="title1">
          <el-form
            ref="form"
            style="
              display: flex;
              justify-content: space-between;
              flex-wrap: wrap;
            "
            :model="form1"
            label-width="80px"
          >
            <!-- <div style="display: flex;justify-content: space-around;flex-wrap: wrap;"> -->
            <div
              style="
                display: flex;
                justify-content: space-between;
                flex-wrap: wrap;
                width: 1640px;
              "
            >
              <el-form-item class="text" label="日期维度" required>
                <el-select
                  v-model="form1.collectType"
                  class="input"
                  placeholder="请选择"
                  style="width: 286px"
                >
                  <el-option label="按天" value="1" />
                  <el-option label="按时间段" value="2" />
                </el-select>
              </el-form-item>
              <el-form-item class="text" label="账单状态">
                <el-select
                  v-model="form1.billStatus"
                  class="input"
                  placeholder="请选择"
                  style="width: 286px"
                >
                  <el-option label="全部" value="1" />
                  <el-option label="已结算" value="2" />
                  <el-option label="未结算" value="3" />
                </el-select>
              </el-form-item>
              <el-form-item class="text" label="承包区名">
                <el-select
                  v-model="form1.goalContractAreaNameId"
                  class="input"
                  placeholder="请选择"
                  style="width: 286px"
                >
                  <el-option
                    v-for="item in ShowCoverAreaList"
                    :key="item.id"
                    :label="item.networkName"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
              <el-form-item class="text" label="业务员名">
                <el-select
                  v-model="form1.solicitorId"
                  class="input"
                  placeholder="请选择"
                  style="width: 286px"
                >
                  <el-option
                    v-for="item in TakeManList"
                    :key="item.id"
                    :label="item.solicitor"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
            </div>
            <el-form-item>
              <el-button @click="onSubmit"
                ><i class="el-icon-upload2" />导出</el-button
              >
            </el-form-item>
          </el-form>
        </div>
        <el-table
          v-if="id === '1'"
          :key="Math.random()"
          v-loading="loading"
          :data="tableData"
          border
          max-height="734"
          max-width="100%"
          :header-cell-style="{ background: '#f6f6f6' }"
          style="width: 100%"
        >
          <el-table-column
            type="index"
            :index="table_index"
            width="50"
            align="center"
          />
          <el-table-column
            prop="networkCode"
            label="网点编号"
            align="center"
            width="100"
          />
          <el-table-column
            prop="name"
            label="网点名称"
            align="center"
            width="100"
          />
          <el-table-column
            prop="contractAreaId"
            label="承包区编码"
            width="100"
            align="center"
          />
          <el-table-column
            prop="networkName.networkName"
            width="100"
            align="center"
            label="承包区"
          />
          <el-table-column
            prop="salesmanId"
            width="100"
            label="业务员编码"
            align="center"
          />
          <el-table-column
            prop="hqSolicitor.solicitor"
            width="100"
            align="center"
            label="业务员名称"
          />
          <el-table-column
            prop="date"
            width="100"
            label="业务日期"
            align="center"
          />
          <el-table-column label="向寄件方收" align="center">
            <el-table-column
              prop="basePaiFeeNumReceipt"
              label="基础派费收费"
              align="center"
            >
              <el-table-column
                prop="basePaiFeeAdjustNumReceipt"
                label="件量"
                align="center"
              />
              <el-table-column
                prop="basePaiFeeReceipt"
                label="金额"
                align="center"
              />
            </el-table-column>
            <el-table-column label="基础派费收费调整" align="center">
              <el-table-column
                prop="basePaiFeeAdjustReceipt"
                label="金额"
                width="140"
                align="center"
              />
            </el-table-column>
            <el-table-column label="正常派件退费" align="center">
              <el-table-column
                prop="normalPaiNumReceipt"
                label="件量"
                width="140"
                align="center"
              />
              <el-table-column
                prop="normalPaiReceipt"
                label="金额"
                width="140"
                align="center"
              />
            </el-table-column>
            <el-table-column label="周期性派费收费" align="center">
              <el-table-column
                prop="periodPaiReceipt"
                label="金额"
                width="140"
                align="center"
              />
            </el-table-column>
            <el-table-column label="大货计重收费" align="center">
              <el-table-column
                prop="bigGoodsReceipt"
                label="金额"
                width="140"
                align="center"
              />
            </el-table-column>
            <el-table-column label="违规重量罚款" align="center">
              <el-table-column
                prop="weightPenaltyNumReceipt"
                label="件量"
                align="center"
              />
              <el-table-column
                prop="weightPenaltyReceipt"
                label="金额"
                align="center"
              />
            </el-table-column>
            <el-table-column label="车线补贴收费" align="center">
              <el-table-column
                prop="carLineReceipt"
                label="金额"
                width="140"
                align="center"
              />
            </el-table-column>
            <el-table-column label="基础派送付费" align="center">
              <el-table-column
                prop="basePaiFeeNumPay"
                label="件量"
                align="center"
              />
              <el-table-column
                prop=" basePaiFeeTotalAmount"
                label="合计金额"
                align="center"
              />
              <el-table-column
                prop="basePaiFeePay"
                label="基础派费金额"
                width="130"
                align="center"
              />
              <el-table-column
                prop="baseKPIAmount"
                label="综合KPI奖励派费金额"
                width="160"
                align="center"
              />
              <el-table-column
                prop="baseKPINum"
                label="综合KPI奖励派费件量"
                width="160"
                align="center"
              />
            </el-table-column>
            <el-table-column label="考核奖励派费" align="center">
              <el-table-column
                prop="incentivePaiFeePay"
                label="金额"
                width="140"
                align="center"
              />
            </el-table-column>
            <el-table-column label="补贴派费付费" align="center">
              <el-table-column
                prop="subsidyPaiFeePay"
                label="金额"
                width="140"
                align="center"
              />
            </el-table-column>
            <el-table-column label="周期性派费付费" align="center">
              <el-table-column
                prop="periodPaiPay"
                label="金额"
                width="140"
                align="center"
              />
            </el-table-column>
            <el-table-column label="大货计重付费" align="center">
              <el-table-column
                prop="bigGoodsPay"
                label="金额"
                width="140"
                align="center"
              />
            </el-table-column>
          </el-table-column>
        </el-table>
        <el-table
          v-if="id === '2'"
          v-loading="loading"
          :data="tableData1"
          border
          max-height="734"
          :header-cell-style="{ background: '#f6f6f6' }"
          style="width: 100%"
        >
          <el-table-column
            type="index"
            :index="table_index"
            width="50"
            align="center"
          />
          <el-table-column
            prop="goalNetworkNameId"
            label="网点编号"
            align="center"
          />
          <el-table-column
            prop="goalNetworkName.networkName"
            label="网点名称"
            align="center"
          />
          <el-table-column
            v-if="value1 === '2' || value1 === '3'"
            prop="goalContractAreaNameId"
            align="center"
            label="承包区编号"
            width="100"
          />
          <el-table-column
            v-if="value1 === '2' || value1 === '3'"
            prop="goalContractAreaName.networkName"
            label="承包区名称"
            width="100"
            align="center"
          />
          <el-table-column
            v-if="value1 === '3'"
            prop="solicitorId"
            align="center"
            width="100"
            label="业务员编号"
          />
          <el-table-column
            v-if="value1 === '3'"
            prop="hqSolicitor.solicitor"
            width="100"
            label="业务员名称"
            align="center"
          />
          <el-table-column
            v-if="value1 === '3'"
            prop="hqSolicitor.name"
            label="证件姓名"
            align="center"
          />
          <el-table-column prop="date" label="业务日期" align="center" />
          <el-table-column label="派费直达应付" align="center">
            <el-table-column
              prop="paiFeeSignNum"
              label="签收量"
              align="center"
            />
            <el-table-column
              prop="paiFeePayNum"
              label="应付量"
              align="center"
            />
            <el-table-column prop="paiFeePay" label="应付金额" align="center" />
            <el-table-column
              prop="paiFeeActualPayNum"
              label="实付件量"
              align="center"
            />
            <el-table-column
              prop="paiFeeActualPay"
              label="实付金额"
              align="center"
            />
            <el-table-column
              prop="paiFeeUnPayNum"
              label="未付件量"
              align="center"
            />
            <el-table-column
              prop="paiFeeUnPay"
              label="未付金额"
              align="center"
            />
          </el-table-column>
          <el-table-column label="送货上门派费直达" align="center">
            <el-table-column
              prop="hdShouldPayPayNum"
              label="应付件量"
              align="center"
            />
            <el-table-column
              prop="hdShouldPayTotalPay"
              label="应付金额-合计"
              width="120"
              align="center"
            />
            <el-table-column
              prop="hdShouldPayFirstWeight"
              label="应付金额-首重"
              width="120"
              align="center"
            />
            <el-table-column
              prop="hdShouldPayContinueWeight"
              label="应付金额-续重"
              width="120"
              align="center"
            />
            <el-table-column
              prop="hdActualPayNum"
              label="实付件量"
              align="center"
            />
            <el-table-column
              prop="hdActualPayTotal"
              label="实付金额-合计"
              width="120"
              align="center"
            />
            <el-table-column
              prop="hdActualPayFirstWeight"
              label="实付金额-首重"
              width="120"
              align="center"
            />
            <el-table-column
              prop="hdActualPayContinueWeight"
              label="实付金额-续重"
              width="120"
              align="center"
            />
            <el-table-column
              prop="hdUnPayNum"
              label="未付件量"
              align="center"
            />
            <el-table-column prop="hdUnPay" label="未付金额" align="center" />
          </el-table-column>
        </el-table>
        <div
          style="
            display: flex;
            justify-content: space-between;
            margin-top: 51px;
          "
        >
          <div class="title2" />
          <div class="block" style="display: flex; justify-content: flex-end">
            <el-pagination
              background
              :current-page="current"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="10"
              layout="total, prev, pager, next"
              :total="+total"
              prev-text="上一页"
              next-text="下一页"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
            />
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {
  ShowCoverAreaApi,
  TakeManApi,
  ClerksBillApi,
  BranchesPaFeiApi,
  BranchesPaFeiApi1,
  BranchesPaFeiApi2,
} from "@/api/HqFinancePanel";
export default {
  components: {},
  data() {
    return {
      loading: false,
      id: "1",
      ProvinceList: [], // 省
      cityList: [], // 市
      value: "",
      value1: "1",
      form: {
        networkName: 1,
        collectType: "",
        contractAreaNameId: "",
        endTime: "",
        pageDate: {
          pageNum: 1,
          pageSize: 10,
        },
        salesmanId: "",
        startTime: "",
      },
      form1: {
        networkName: "",
        billStatus: "",
        collectType: "",
        endTime: "",
        goalContractAreaNameId: "",
        pageDate: {
          pageNum: 1,
          pageSize: 10,
        },
        solicitorId: "",
        startTime: "",
      },
      tableData: [],
      tableData1: [],
      current: 0, // 页数
      pages: 0, // 条数
      total: 0, // 总数
      ShowCoverAreaList: [], // 承包区列表
      TakeManList: [], // 业务员名称列表
    };
  },
  created() {
    this.ShowCoverArea();
    this.TakeMan();
  },
  methods: {
    handleSizeChange(val) {
      this.form.pageDate.pageSize = val;
      this.onSubmit();
    },
    handleCurrentChange(val) {
      this.form.pageDate.pageNum = val;
      this.onSubmit();
    },
    // 序号
    table_index(index) {
      return (
        (this.form.pageDate.pageNum - 1) * this.form.pageDate.pageSize +
        index +
        1
      );
    },
    // tab切换
    tab(e) {
      this.id = e;
      this.khClear();
    },
    // 选择时间
    changeTime() {
      if (this.value != null) {
        this.form.startTime = this.value[0];
        this.form.endTime = this.value[1];
      }
    },
    // 承包区
    async ShowCoverArea() {
      const res = await ShowCoverAreaApi();
      this.ShowCoverAreaList = res.data;
    },
    // 业务员名称列表
    async TakeMan() {
      const res = await TakeManApi();
      this.TakeManList = res.data;
    },
    table(res) {
      this.tableData1 = res.data.data;
      this.total = res.data.total;
      this.current = res.data.current;
      this.pages = res.data.pages;
    },
    // 查询
    async onSubmit() {
      this.loading = true;
      if (this.id === "1") {
        const res = await ClerksBillApi(this.form);
        if (res.code == 200) {
          this.tableData = res.data.data;
          this.total = res.data.total;
          this.current = res.data.current;
          this.pages = res.data.pages;
        }
      } else if (this.id === "2" && this.value1 != "") {
        let res = null;
        if (this.value1 === "1") {
          res = await BranchesPaFeiApi(this.form1);
        } else if (this.value1 === "2") {
          res = await BranchesPaFeiApi1(this.form1);
        } else if (this.value1 === "3") {
          res = await BranchesPaFeiApi2(this.form1);
        }
        if (res.code == 200) {
          this.table(res);
        }
      }
      this.loading = false;
    },
    changeType() {
      this.tableData1 = [];
    },
    // 重置
    khClear() {
      if (this.id === "1") {
        Object.keys(this.form).forEach((key) => {
          if (key !== "pageDate") {
            this.form[key] = "";
          }
        });
        this.tableData = [];
      } else if (this.id === "2") {
        Object.keys(this.form1).forEach((key) => {
          if (key !== "pageDate") {
            this.form1[key] = "";
          }
        });
        this.tableData1 = [];
        this.value1 = "1";
      }
      this.value = "";
      this.total = 0;
      this.current = 0;
      this.pages = 0;
    },
  },
};
</script>
<style scoped lang="scss">
.tit {
  display: flex;

  .tex1 {
    margin-right: 48px;
    font-size: 16px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;
    background: #fff;
    border: 1px #fff solid;
  }

  .active {
    font-family: Source Han Sans CN;
    font-weight: 700;
    color: #2087d0;
    position: relative;
  }

  .active::before {
    position: absolute;
    content: "";
    width: 110px;
    height: 2px;
    background: #2087d0;
    border-radius: 1px;
    bottom: -21px;
    left: 49%;
    transform: translate(-50%);
  }
}

.head {
  padding: 30px;
}

.title {
  font-size: 16px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
  margin-top: 20px;
}

.line {
  height: 1px;
  background: #d8d8d8;
  border-radius: 1px;
  margin-top: 19px;
}

.title1 {
  // display: flex;
  // justify-content: space-between;
  .text {
    font-size: 18px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;

    // margin-left: 52px;
    .input {
      width: 286px;
      height: 36px;
      background: #ffffff;
      // border: 1px solid #B4B4B4;
      border-radius: 4px;
    }

    .input1 {
      width: 708px;
      height: 36px;
      background: #ffffff;
      border: 1px solid #b4b4b4;
      border-radius: 4px;
    }
  }
}

.title2 {
  font-size: 18px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
}
</style>
